namespace SubSonic
{
    using SubSonic.Utilities;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Text;
    using System.Web;
    using System.Web.UI.WebControls;

    public class Query
    {
        private string _logicalDeleteColumn;
        private DataProvider _provider;
        private string _providerName;
        internal List<BetweenAnd> betweens;
        private int commandTimeout;
        internal string inColumn;
        internal object[] inList;
        private bool isDistinct;
        private SubSonic.OrderByCollection orderByCollection;
        private int pageIndex;
        private int pageSize;
        private SubSonic.QueryType queryType;
        private string selectList;
        private TableSchema.Table table;
        private string top;
        private Hashtable updateSettings;
        internal List<Where> wheres;

        public Query(TableSchema.Table tbl)
        {
            this.commandTimeout = 60;
            this.pageSize = 20;
            this.pageIndex = -1;
            this.top = "100 PERCENT";
            this.selectList = " * ";
            this.orderByCollection = new SubSonic.OrderByCollection();
            this._providerName = string.Empty;
            this.inColumn = string.Empty;
            if (tbl == null)
            {
                throw new Exception("The Schema Table you passed in is null. If you've added a constructor to a class, make sure you reference 'GetTableSchema()' on the top line, so that the static schema is loaded.");
            }
            if (tbl.Columns == null)
            {
                throw new Exception("The Schema Table you passed in has no columns");
            }
            this.ProviderName = tbl.Provider.Name;
            this.Provider = tbl.Provider;
            this.table = tbl;
            this.SetLists();
        }

        public Query(string tableName)
        {
            this.commandTimeout = 60;
            this.pageSize = 20;
            this.pageIndex = -1;
            this.top = "100 PERCENT";
            this.selectList = " * ";
            this.orderByCollection = new SubSonic.OrderByCollection();
            this._providerName = string.Empty;
            this.inColumn = string.Empty;
            this.table = BuildTableSchema(tableName);
            this.Provider = this.table.Provider;
            this.SetLists();
        }

        public Query(string tableName, string providerName)
        {
            this.commandTimeout = 60;
            this.pageSize = 20;
            this.pageIndex = -1;
            this.top = "100 PERCENT";
            this.selectList = " * ";
            this.orderByCollection = new SubSonic.OrderByCollection();
            this._providerName = string.Empty;
            this.inColumn = string.Empty;
            this.table = BuildTableSchema(tableName, providerName);
            this.ProviderName = providerName;
            this.Provider = this.table.Provider;
            this.SetLists();
        }

        public Query AddBetweenAnd(BetweenAnd between)
        {
            if (string.IsNullOrEmpty(between.TableName))
            {
                between.TableName = this.table.Name;
            }
            this.betweens.Add(between);
            return this;
        }

        public Query AddBetweenAnd(string columName, DateTime dateStart, DateTime dateEnd)
        {
            this.AddBetweenAnd(this.table.Name, columName, dateStart, dateEnd);
            return this;
        }

        public Query AddBetweenAnd(string tableName, string columName, DateTime dateStart, DateTime dateEnd)
        {
            this.AddBetweenAnd(tableName, columName, dateStart, dateEnd, Where.WhereCondition.AND);
            return this;
        }

        public Query AddBetweenAnd(string tableName, string columName, DateTime dateStart, DateTime dateEnd, Where.WhereCondition condition)
        {
            BetweenAnd between = new BetweenAnd();
            between.ColumnName = columName;
            between.TableName = tableName;
            between.StartDate = dateStart;
            between.EndDate = dateEnd;
            between.Condition = condition;
            between.StartParameterName = "start" + between.ColumnName + this.betweens.Count;
            between.EndParameterName = "end" + between.ColumnName + this.betweens.Count;
            this.AddBetweenAnd(between);
            return this;
        }

        public Query AddBetweenValues(string columnName, object value1, object value2)
        {
            this.AddWhere(columnName, Comparison.GreaterOrEquals, value1);
            this.AddWhere(this.table.Name, columnName + "2", columnName, Comparison.LessOrEquals, value2);
            return this;
        }

        private void AddQueryToCollection(SubSonic.OrderBy orderBy)
        {
            if (this.OrderByCollection.Count > 0)
            {
                orderBy.TrimDirective();
            }
            this.OrderByCollection.Add(orderBy);
        }

        public Query AddUpdateSetting(string columnName, object value)
        {
            if (Utility.IsMatch(value.ToString(), bool.FalseString))
            {
                value = 0;
            }
            else if (Utility.IsMatch(value.ToString(), bool.TrueString))
            {
                value = 1;
            }
            if (this.updateSettings == null)
            {
                this.updateSettings = new Hashtable();
            }
            if (this.updateSettings.Contains(columnName))
            {
                this.updateSettings.Remove(columnName);
            }
            this.updateSettings.Add(columnName, value);
            this.QueryType = SubSonic.QueryType.Update;
            return this;
        }

        public Query AddWhere(Where where)
        {
            where.ParameterName = Utility.PrefixParameter(where.ParameterName.Trim() + this.wheres.Count, this.Provider);
            where.DbType = this.GetDbType(where.ColumnName.Trim());
            this.wheres.Add(where);
            if (string.IsNullOrEmpty(where.TableName))
            {
                where.TableName = this.table.Name;
                TableSchema.TableColumn column = this.table.GetColumn(where.ColumnName);
                if (column != null)
                {
                    where.DbType = column.DataType;
                }
            }
            return this;
        }

        public Query AddWhere(string columnName, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query AddWhere(string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, comp, paramValue);
            return this;
        }

        public Query AddWhere(string tableName, string columnName, object paramValue)
        {
            this.AddWhere(tableName, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query AddWhere(string tableName, string columnName, Comparison comp, object paramValue)
        {
            return this.AddWhere(tableName, columnName, columnName, comp, paramValue, Where.WhereCondition.AND);
        }

        public Query AddWhere(string tableName, string parameterName, string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(tableName, parameterName, columnName, comp, paramValue, Where.WhereCondition.AND);
            return this;
        }

        public Query AddWhere(string tableName, string parameterName, string columnName, Comparison comp, object paramValue, Where.WhereCondition condition)
        {
            Where where = new Where();
            where.ColumnName = columnName;
            where.ParameterValue = paramValue;
            where.Comparison = comp;
            where.TableName = tableName;
            where.Condition = condition;
            this.AddWhere(where);
            return this;
        }

        public Query AND(string expression)
        {
            Where where = Where.ParseExpression(expression, Where.WhereCondition.AND);
            if (where != null)
            {
                where.TableName = this.table.Name;
                where.DbType = this.GetDbType(where.ColumnName);
                this.AddWhere(where);
            }
            return this;
        }

        public Query AND(string columnName, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query AND(string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, comp, paramValue);
            return this;
        }

        public Query AND(string tableName, string columnName, object paramValue)
        {
            this.AddWhere(tableName, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query AND(string tableName, string columnName, Comparison comp, object paramValue)
        {
            return this.AddWhere(tableName, columnName, columnName, comp, paramValue);
        }

        public Query BETWEEN_AND(string columName, DateTime dateStart, DateTime dateEnd)
        {
            this.AddBetweenAnd(this.table.Name, columName, dateStart, dateEnd);
            return this;
        }

        public Query BETWEEN_AND(string columName, string dateTimeStart, string dateTimeEnd)
        {
            this.BETWEEN_AND(columName, DateTime.Parse(dateTimeStart), DateTime.Parse(dateTimeEnd));
            return this;
        }

        public Query BETWEEN_AND(string tableName, string columName, DateTime dateStart, DateTime dateEnd, Where.WhereCondition condition)
        {
            this.AddBetweenAnd(tableName, columName, dateStart, dateEnd, condition);
            return this;
        }

        public Query BETWEEN_VALUES(string columnName, object value1, object value2)
        {
            this.AddBetweenValues(columnName, value1, value2);
            return this;
        }

        public QueryCommand BuildCommand()
        {
            return DataService.BuildCommand(this);
        }

        public QueryCommand BuildDeleteCommand()
        {
            this.queryType = SubSonic.QueryType.Delete;
            return DataService.BuildCommand(this);
        }

        public QueryCommand BuildSelectCommand()
        {
            this.queryType = SubSonic.QueryType.Select;
            return DataService.BuildCommand(this);
        }

        public static TableSchema.Table BuildTableSchema(string tableName)
        {
            return BuildTableSchema(tableName, string.Empty);
        }

        public static TableSchema.Table BuildTableSchema(string tableName, string providerName)
        {
            return DataService.GetTableSchema(tableName, providerName);
        }

        public QueryCommand BuildUpdateCommand()
        {
            this.queryType = SubSonic.QueryType.Update;
            return DataService.BuildCommand(this);
        }

        internal void CheckLogicalDelete()
        {
            foreach (Where where in this.wheres)
            {
                if (Utility.IsLogicalDeleteColumn(where.ColumnName))
                {
                    return;
                }
            }
            foreach (TableSchema.TableColumn column in this.Schema.Columns)
            {
                if (Utility.IsLogicalDeleteColumn(column.ColumnName))
                {
                    this.LogicalDeleteColumn = column.ColumnName;
                    break;
                }
            }
        }

        public Query DISTINCT()
        {
            this.isDistinct = true;
            return this;
        }

        public void Execute()
        {
            DataService.ExecuteQuery(this.GetCommand());
        }

        private object ExecuteAggregate(string columnName, string aggregateFunction, bool isDistinctQuery)
        {
            QueryCommand cmd = new QueryCommand(("SELECT " + Utility.MakeFunction(aggregateFunction, columnName, isDistinctQuery, this.Provider) + " FROM " + this.Provider.DelimitDbName(this.Schema.Name)) + DataProvider.BuildWhere(this));
            DataProvider.AddWhereParameters(cmd, this);
            return DataService.ExecuteScalar(cmd);
        }

        private object ExecuteAggregate(string columnName, Where where, string aggregateFunction, bool isDistinctQuery)
        {
            QueryCommand cmd = new QueryCommand("SELECT " + Utility.MakeFunction(aggregateFunction, columnName, isDistinctQuery, this.Provider) + " FROM " + this.Provider.DelimitDbName(this.Schema.Name), this.ProviderName);
            if (where != null)
            {
                string commandSql = cmd.CommandSql;
                cmd.CommandSql = commandSql + " WHERE " + this.Provider.DelimitDbName(where.ColumnName) + Where.GetComparisonOperator(where.Comparison) + Utility.PrefixParameter("p1", this.Provider);
                cmd.AddParameter("p1", where.ParameterValue);
            }
            return DataService.ExecuteScalar(cmd);
        }

        public DataSet ExecuteDataSet()
        {
            return DataService.GetDataSet(this.GetCommand());
        }

        public T ExecuteDataSet<T>() where T: DataSet, new()
        {
            return DataService.GetDataSet<T>(this.GetCommand());
        }

        public DataSet ExecuteJoinedDataSet()
        {
            return this.ExecuteJoinedDataSet<DataSet>();
        }

        public T ExecuteJoinedDataSet<T>() where T: DataSet, new()
        {
            string str = "SELECT ";
            string str2 = " FROM " + Utility.QualifyTableName(this.table.SchemaName, this.table.TableName, this.table.Provider);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < this.table.Columns.Count; i++)
            {
                StringBuilder builder2;
                string columnName;
                string str3 = " INNER JOIN ";
                TableSchema.TableColumn column = this.table.Columns[i];
                if (column.IsNullable)
                {
                    str3 = " LEFT JOIN ";
                }
                if (column.IsForeignKey && !string.IsNullOrEmpty(column.ForeignKeyTableName))
                {
                    string tableName = "J" + i;
                    TableSchema.Table table = DataService.GetSchema(column.ForeignKeyTableName, this.ProviderName, TableType.Table);
                    columnName = table.Columns[1].ColumnName;
                    string str6 = Utility.QualifyColumnName(tableName, columnName, this.table.Provider);
                    builder2 = new StringBuilder(str6);
                    builder.Append(str3);
                    builder.Append(this.table.Provider.DelimitDbName(table.Name));
                    builder.Append(" ");
                    builder.Append(tableName);
                    builder.Append(" ON ");
                    string str7 = Utility.QualifyColumnName(this.table.Name, column.ColumnName, this.table.Provider);
                    builder.Append(str7);
                    builder.Append(" = ");
                    string str8 = Utility.QualifyColumnName(tableName, table.PrimaryKey.ColumnName, this.table.Provider);
                    builder.Append(str8);
                    if (this.OrderByCollection.Count > 0)
                    {
                        foreach (SubSonic.OrderBy by in this.OrderByCollection)
                        {
                            by.OrderString = by.OrderString.Replace(str7, str6);
                        }
                    }
                }
                else
                {
                    columnName = column.ColumnName;
                    builder2 = new StringBuilder(Utility.QualifyColumnName(this.table.Name, columnName, this.table.Provider));
                }
                builder2.Append(" AS ");
                builder2.Append(column.ColumnName);
                if ((i + 1) != this.table.Columns.Count)
                {
                    builder2.Append(", ");
                }
                str = str + builder2;
            }
            StringBuilder builder3 = new StringBuilder();
            builder3.Append(str);
            builder3.Append(str2);
            builder3.Append(builder);
            if (this.OrderByCollection.Count > 0)
            {
                for (int j = 0; j < this.orderByCollection.Count; j++)
                {
                    string orderString = this.OrderByCollection[j].OrderString;
                    if (!string.IsNullOrEmpty(orderString))
                    {
                        builder3.Append(orderString);
                        if ((j + 1) != this.OrderByCollection.Count)
                        {
                            builder3.Append(", ");
                        }
                    }
                }
            }
            QueryCommand cmd = new QueryCommand(builder3.ToString(), this.table.Provider.Name);
            return DataService.GetDataSet<T>(cmd);
        }

        public IDataReader ExecuteReader()
        {
            return DataService.GetReader(this.GetCommand());
        }

        public object ExecuteScalar()
        {
            return DataService.ExecuteScalar(this.GetCommand());
        }

        public object GetAverage(string columnName)
        {
            return this.ExecuteAggregate(columnName, "AVG", this.IsDistinct);
        }

        public object GetAverage(string columnName, Where where)
        {
            return this.ExecuteAggregate(columnName, where, "AVG", this.IsDistinct);
        }

        private QueryCommand GetCommand()
        {
            QueryCommand command = null;
            switch (this.QueryType)
            {
                case SubSonic.QueryType.Select:
                    command = this.BuildSelectCommand();
                    break;

                case SubSonic.QueryType.Update:
                    command = this.BuildUpdateCommand();
                    break;

                case SubSonic.QueryType.Insert:
                    command = null;
                    break;

                case SubSonic.QueryType.Delete:
                    command = this.BuildDeleteCommand();
                    break;
            }
            if (command != null)
            {
                command.ProviderName = this.ProviderName;
            }
            return command;
        }

        public static string GetComparisonOperator(Comparison comp)
        {
            return Where.GetComparisonOperator(comp);
        }

        public int GetCount(string columnName)
        {
            return (int) this.ExecuteAggregate(columnName, "COUNT", this.IsDistinct);
        }

        public int GetCount(string columnName, Where where)
        {
            return (int) this.ExecuteAggregate(columnName, where, "COUNT", this.IsDistinct);
        }

        private DbType GetDbType(string columnName)
        {
            TableSchema.TableColumn column = this.table.GetColumn(columnName);
            if (column == null)
            {
                throw new Exception("There is no column named '" + columnName + "' in table " + this.table.Name);
            }
            return column.DataType;
        }

        public object GetMax(string columnName)
        {
            return this.ExecuteAggregate(columnName, "MAX", false);
        }

        public object GetMax(string columnName, Where where)
        {
            return this.ExecuteAggregate(columnName, where, "MAX", false);
        }

        public object GetMin(string columnName)
        {
            return this.ExecuteAggregate(columnName, "MIN", false);
        }

        public object GetMin(string columnName, Where where)
        {
            return this.ExecuteAggregate(columnName, where, "MIN", false);
        }

        public int GetRecordCount()
        {
            return DataService.GetRecordCount(this);
        }

        public string GetSql()
        {
            return DataService.GetSql(this);
        }

        public object GetSum(string columnName)
        {
            return this.ExecuteAggregate(columnName, "SUM", this.IsDistinct);
        }

        public object GetSum(string columnName, Where where)
        {
            return this.ExecuteAggregate(columnName, where, "SUM", this.IsDistinct);
        }

        public Query IN(string columnName, object[] listItems)
        {
            this.inColumn = columnName;
            this.inList = listItems;
            return this;
        }

        public Query IN(string columnName, ArrayList listItems)
        {
            this.inColumn = columnName;
            this.inList = new object[listItems.Count];
            for (int i = 0; i < listItems.Count; i++)
            {
                this.inList[i] = listItems[i];
            }
            return this;
        }

        public Query IN(string columnName, ListItemCollection listItems)
        {
            this.inColumn = columnName;
            this.inList = new object[listItems.Count];
            int index = 0;
            foreach (ListItem item in listItems)
            {
                if (item.Selected)
                {
                    this.inList[index] = item.Value;
                    index++;
                }
            }
            return this;
        }

        public string Inspect()
        {
            bool flag = HttpContext.Current != null;
            DateTime now = DateTime.Now;
            StringBuilder builder = new StringBuilder();
            DataSet dataSet = DataService.GetDataSet(this.GetCommand());
            DateTime time2 = DateTime.Now;
            TimeSpan span = new TimeSpan(time2.Ticks - now.Ticks);
            if (flag)
            {
                builder.Append("<h2>Query Inspection: " + this.Schema.Name + "</h2>");
                builder.Append("<b>Execution Time:</b> " + span.Milliseconds + " milliseconds <br/><br/>");
                builder.Append("<b>Query: </b><xmp>" + this.GetSql() + "</xmp><br/><br/>");
                builder.Append(DataProvider.BuildWhere(this));
                builder.Append("<br/>");
            }
            else
            {
                builder.Append("Query Inspection: " + this.Schema.Name + Environment.NewLine);
                builder.Append(string.Concat(new object[] { "Execution Time: ", span.Milliseconds, " milliseconds", Environment.NewLine, Environment.NewLine }));
                builder.Append("Query: " + this.GetSql() + Environment.NewLine + Environment.NewLine);
                builder.Append(DataProvider.BuildWhere(this));
                builder.Append(Environment.NewLine);
            }
            if (dataSet != null)
            {
                if (dataSet.Tables.Count > 0)
                {
                    DataTable tbl = dataSet.Tables[0];
                    if (flag)
                    {
                        builder.Append("<b>Total Records:</b> ");
                        builder.Append(dataSet.Tables[0].Rows.Count.ToString());
                        builder.Append("<br/><br/>");
                        builder.Append(Utility.DataTableToHTML(tbl, "80%"));
                    }
                    else
                    {
                        builder.Append("Total Records: ");
                        builder.Append(dataSet.Tables[0].Rows.Count.ToString());
                    }
                }
            }
            else
            {
                builder.Append("No Data");
            }
            return builder.ToString();
        }

        public Query OR(string expression)
        {
            Where where = Where.ParseExpression(expression, Where.WhereCondition.OR);
            if (where != null)
            {
                where.TableName = this.table.Name;
                where.DbType = this.GetDbType(where.ColumnName);
                this.AddWhere(where);
            }
            return this;
        }

        public Query OR(string columnName, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, columnName, Comparison.Equals, paramValue, Where.WhereCondition.OR);
            return this;
        }

        public Query OR(string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, columnName, comp, paramValue, Where.WhereCondition.OR);
            return this;
        }

        public Query OR(string tableName, string columnName, object paramValue)
        {
            this.AddWhere(tableName, columnName, columnName, Comparison.Equals, paramValue, Where.WhereCondition.OR);
            return this;
        }

        public Query OR(string tableName, string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(tableName, columnName, columnName, comp, paramValue, Where.WhereCondition.OR);
            return this;
        }

        public Query OR_BETWEEN_AND(string columName, DateTime dateStart, DateTime dateEnd)
        {
            this.AddBetweenAnd(this.table.Name, columName, dateStart, dateEnd, Where.WhereCondition.OR);
            return this;
        }

        public Query OR_BETWEEN_AND(string columName, string dateTimeStart, string dateTimeEnd)
        {
            this.OR_BETWEEN_AND(columName, DateTime.Parse(dateTimeStart), DateTime.Parse(dateTimeEnd));
            return this;
        }

        public Query ORDER_BY(TableSchema.TableColumn col)
        {
            return this.ORDER_BY(col, " ASC");
        }

        public Query ORDER_BY(string orderExpression)
        {
            this.AddQueryToCollection(SubSonic.OrderBy.PassedValue(orderExpression));
            return this;
        }

        public Query ORDER_BY(TableSchema.TableColumn col, string sortDirection)
        {
            if (string.IsNullOrEmpty(sortDirection) || Utility.IsMatch(sortDirection, " ASC", true))
            {
                this.AddQueryToCollection(SubSonic.OrderBy.Asc(col));
            }
            else if (Utility.IsMatch(sortDirection, " DESC", true))
            {
                this.AddQueryToCollection(SubSonic.OrderBy.Desc(col));
            }
            return this;
        }

        public Query ORDER_BY(string orderExpression, string sortDirection)
        {
            sortDirection = sortDirection.Trim();
            if (!string.IsNullOrEmpty(sortDirection))
            {
                if (Utility.IsMatch(sortDirection, " ASC", true))
                {
                    this.AddQueryToCollection(SubSonic.OrderBy.Asc(orderExpression));
                }
                else if (Utility.IsMatch(sortDirection, " DESC", true))
                {
                    this.AddQueryToCollection(SubSonic.OrderBy.Desc(orderExpression));
                }
            }
            else
            {
                this.ORDER_BY(orderExpression);
            }
            return this;
        }

        public Query ORDER_BY(TableSchema.TableColumn col, string sortDirection, string tableAlias)
        {
            if (string.IsNullOrEmpty(tableAlias))
            {
                return this.ORDER_BY(col, sortDirection);
            }
            if (string.IsNullOrEmpty(sortDirection) || Utility.IsMatch(sortDirection, " ASC", true))
            {
                this.AddQueryToCollection(SubSonic.OrderBy.Asc(col, tableAlias));
            }
            else if (Utility.IsMatch(sortDirection, " DESC", true))
            {
                this.AddQueryToCollection(SubSonic.OrderBy.Desc(col, tableAlias));
            }
            return this;
        }

        private void SetLists()
        {
            this.wheres = new List<Where>();
            this.betweens = new List<BetweenAnd>();
            this.updateSettings = new Hashtable();
        }

        public Query WHERE(string expression)
        {
            Where where = Where.ParseExpression(expression, Where.WhereCondition.AND);
            if (where != null)
            {
                where.TableName = this.table.Name;
                where.DbType = this.GetDbType(where.ColumnName);
                this.AddWhere(where);
            }
            return this;
        }

        public Query WHERE(string columnName, IConstraint constraint)
        {
            this.AddWhere(this.table.Name, columnName, constraint.Comparison, constraint.Value);
            return this;
        }

        public Query WHERE(string columnName, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query WHERE(string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(this.table.Name, columnName, comp, paramValue);
            return this;
        }

        public Query WHERE(string tableName, string columnName, object paramValue)
        {
            this.AddWhere(tableName, columnName, Comparison.Equals, paramValue);
            return this;
        }

        public Query WHERE(string tableName, string columnName, Comparison comp, object paramValue)
        {
            return this.AddWhere(tableName, columnName, columnName, comp, paramValue);
        }

        public Query WHERE(string tableName, string parameterName, string columnName, Comparison comp, object paramValue)
        {
            this.AddWhere(tableName, parameterName, columnName, comp, paramValue, Where.WhereCondition.AND);
            return this;
        }

        public Query WHERE(string tableName, string parameterName, string columnName, Comparison comp, object paramValue, Where.WhereCondition condition)
        {
            this.AddWhere(tableName, parameterName, columnName, comp, paramValue, condition);
            return this;
        }

        public int CommandTimeout
        {
            get
            {
                return this.commandTimeout;
            }
            set
            {
                this.commandTimeout = value;
            }
        }

        public bool IsDistinct
        {
            get
            {
                return this.isDistinct;
            }
            set
            {
                this.isDistinct = value;
            }
        }

        public string LogicalDeleteColumn
        {
            get
            {
                return this._logicalDeleteColumn;
            }
            set
            {
                this._logicalDeleteColumn = value;
            }
        }

        public SubSonic.OrderBy OrderBy
        {
            get
            {
                if (this.orderByCollection.Count > 0)
                {
                    return this.orderByCollection[0];
                }
                return null;
            }
            set
            {
                this.orderByCollection.Clear();
                this.orderByCollection.Add(value);
            }
        }

        public SubSonic.OrderByCollection OrderByCollection
        {
            get
            {
                return this.orderByCollection;
            }
            set
            {
                this.orderByCollection = value;
            }
        }

        public int PageIndex
        {
            get
            {
                return this.pageIndex;
            }
            set
            {
                this.pageIndex = value;
            }
        }

        public int PageSize
        {
            get
            {
                return this.pageSize;
            }
            set
            {
                this.pageSize = value;
            }
        }

        public DataProvider Provider
        {
            get
            {
                return this._provider;
            }
            set
            {
                this._provider = value;
            }
        }

        public string ProviderName
        {
            get
            {
                return this._providerName;
            }
            set
            {
                this._providerName = value;
            }
        }

        public SubSonic.QueryType QueryType
        {
            get
            {
                return this.queryType;
            }
            set
            {
                this.queryType = value;
            }
        }

        public TableSchema.Table Schema
        {
            get
            {
                return this.table;
            }
            set
            {
                this.table = value;
            }
        }

        public string SelectList
        {
            get
            {
                return this.selectList;
            }
            set
            {
                this.selectList = value;
            }
        }

        public string Top
        {
            get
            {
                return this.top;
            }
            set
            {
                this.top = value;
            }
        }

        internal Hashtable UpdateSettings
        {
            get
            {
                return this.updateSettings;
            }
        }
    }
}

